# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
触发中移动项目的接口  post_msydloan_batch
只处理放款
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

import time
from datetime import datetime

from interfacetest.baseset.test_logger import Logger
from api_msydloan_web import create_loanFile, upload_loanFile
from pythonlession.recordmodule.paramiko_model import SftpDeal

logger = Logger("post_msydloan_batch").get_log()

def deal_sftp():
    folder = '/data/sftp/hb/home/upload/hb/send/'
    date = datetime.now().strftime('%Y%m%d')
    sftp = SftpDeal()
    provs = ['05','18','23']
    for p in provs:
        # 1. 生成dat文件
        #file = get_file('01', p, date)          # 初始生成
        file = 'F:\\HBCBF_' +p +'_888190900238401_01_' + date +'_001.DAT'
        remote_dat = folder + date +'/'+ file.split('\\')[1]
        sftp.upload(file,remote_dat)         # 2. 上传dat文件
    # 处理xls文件
    xls_file = 'F:/' + date + 'loanFile.xls'
    remote_xls = folder + date + '/' + xls_file.split('/')[1]
    time.sleep(2)                   # 3. 删除旧的xls文件
    sftp.remove(remote_xls)
    time.sleep(2)                   # 4. web端生成xls文件
    create_loanFile(date)
    time.sleep(2)                   # 5. 下载xls文件到本地
    sftp.download(remote_xls,xls_file)
    time.sleep(2)                   # 6. 本地xls放款文件导入
    upload_loanFile(xls_file,date)


if __name__ == '__main__':
    deal_sftp()



